<template>
    <div>
        <el-breadcrumb separator="/" class="m-b-25">
            <el-breadcrumb-item><a href="/">后台首页</a></el-breadcrumb-item>
            <el-breadcrumb-item><a href="/admin">管理员管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>添加管理员</el-breadcrumb-item>
        </el-breadcrumb>

        <el-form ref="form" :model="form" label-width="100px" class="m-t-10">
            <el-form-item label="管理员账号">
                <el-input ref="username" v-model="form.username" placeholder="请输入管理员账号"></el-input>
            </el-form-item>

            <el-form-item label="管理员密码">
                <el-input ref="password" v-model="form.password" placeholder="请输入管理员密码" show-password></el-input>
            </el-form-item>

            <el-form-item label="管理员昵称">
                <el-input ref="nickname" v-model="form.nickname" placeholder="请输入管理员昵称"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="success" @click="submit">添加</el-button>
                <el-button @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {
        post
    } from '@/network/request'
    export default {
        name: 'AddAdmin',
        data() {
            return {
                form: {
                    username: '',
                    password: '',
                    nickname: ''
                }
            }
        },
        methods: {
            submit() {
                if (this.form.username == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理员账号',
                        offset: 60
                    })
                    this.$refs['username'].focus()
                    return false
                }
                if (this.form.password == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理员密码',
                        offset: 60
                    })
                    this.$refs['password'].focus()
                    return false
                }
                if (this.form.nickname == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理员昵称',
                        offset: 60
                    })
                    this.$refs['nickname'].focus()
                    return false
                }
                post('/addAdmin', this.form).then(res => {
                    const result = res.data
                    if (result.code == 200) {
                        this.$notify.success({
                            title: '系统提示',
                            message: '管理员添加成功',
                            offset: 60
                        })
                        this.$router.push('/admin')
                    }
                }).catch()
            },
            cancel() {
                this.$router.push('/admin')
            }
        }
    }
</script>

<style scoped>

</style>